package io.renren.common.utils;

import com.alibaba.fastjson.JSONArray;
import io.renren.modules.psorder.entity.PsOrderEntity;
import net.sf.json.JSONObject;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wdj
 * 推送返回json格式结果工具类
 * 2016年12月5日
 * qq:2230419705*/
public class QmPushMsgUtils {

	/**
	 * 推送配送订单给出车的司机
	 * @param statuCode
	 * @param msg
	 * @param psOrder
	 * @return
	 */
	public static String pushPsOrderToDriver(String statuCode, String msg, PsOrderEntity psOrder, JSONArray destinationJsonArray) {
		Map<String,Object> map1 = new HashMap<String, Object>();
		map1.put("statuCode", statuCode);
		map1.put("msg", msg);
		
//		Map<String,String> map2 = new HashMap<String, String>();
//		map2.put("psOrder", JSONObject.fromObject(psOrder).toString());

		//此法可以排除掉一些不需要属性
		JSONObject ex = IgnoreFieldProcessorImpl.JsonConfig(new String[]{"ordernum","driverTel","startLat","startLng",
				"endLat","endLng","driverId","extraCharge","extraChargeNote","startingPrice","totalPrice","orderStatus","payType",
				"startName","startNameDetail","endName","endNameDetail","orderMoney","vehicleType","userPhone","receiverName","overMilegePrice",
				"waitMinutes","payRealymoney","appointment","appointmentTime","isCollected","isEvaluated"}, psOrder);

		//对订单时间进行格式化 ,上面的排除属性方法以及包含格式化时间了
		/*JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
		JSONObject json = new JSONObject();
		if (destinationJsonArray != null) {
			psOrder.setDestinationJsonArray(destinationJsonArray);
		}
		JSONObject ex = json.fromObject(psOrder, jsonConfig);*/


//		ex.put("destinationData", destinationJsonArray);
		map1.put("data", ex); //ex.toString()
//		if (destinationJsonArray != null) {
//			map1.put("destinationData", destinationJsonArray);
//		}
		JSONObject jsonObject = JSONObject.fromObject(map1);
		return jsonObject.toString();
	}
	
	/**
	 * 1.反馈被接订单号给用户
	 * 2.反馈快车订单完成给用户
	 * @param statuCode
	 * @param msg
	 * @param psOrder
	 * @return
	 */
	public static String pushPsOrderToUser(String statuCode, String msg, PsOrderEntity psOrder, JSONArray destinationJsonArray) {
		Map<String,Object> map1 = new HashMap<String, Object>();
		map1.put("statuCode", statuCode);
		map1.put("msg", msg);

//		Map<String,String> map2 = new HashMap<String, String>();
//		map2.put("orderNum", orderNum);
//		map2.put("driverId", driverId);

		//此法可以排除掉一些不需要属性
		JSONObject ex = IgnoreFieldProcessorImpl.JsonConfig(new String[]{"ordernum","driverTel","startLat","startLng",
				"endLat","endLng","driverId","extraCharge","extraChargeNote","startingPrice","totalPrice","orderStatus","payType",
				"startName","startNameDetail","endName","endNameDetail","orderMoney","vehicleType","userPhone","receiverName","overMilegePrice",
		        "waitMinutes","payRealymoney","appointment","appointmentTime","isCollected","isEvaluated"}, psOrder);

		map1.put("data", ex); //ex.toString()
//		if (destinationJsonArray != null) {
//			map1.put("destinationData", destinationJsonArray);
//		}
		JSONObject jsonObject = JSONObject.fromObject(map1);
		return jsonObject.toString();
	}

	/**
	 * 以前的模板,可无视
	 * @param statuCode
	 * @param msg
	 * @param content
	 * @return
	 */
	public static String pushFastRegToDriver(String statuCode,String msg,String content) {
		Map<String,Object> map1 = new HashMap<String, Object>();
		map1.put("statuCode", statuCode);
		map1.put("msg", msg);

		Map<String,String> map2 = new HashMap<String, String>();
		map2.put("content", content);
		map1.put("data", map2);
		JSONObject jsonObject = JSONObject.fromObject(map1);
		return jsonObject.toString();
	}



	
	
	
}
